﻿using System;
namespace Producers.Karis.Xtee.Riik.Ee.Producer.Karis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="krUurijaJIsik_id_vastus", Namespace="http://producers.karis.xtee.riik.ee/producer/karis", Target=typeof(KrUurijaJIsikIdVastus))]
    public class KrUurijaJIsikIdVastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKrUurijaJIsikIdVastus clazz;
        
        public KrUurijaJIsikIdVastusSerializer(IKrUurijaJIsikIdVastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ttJIsik");
            if (clazz.TtJIsik!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("jisik_karistus", "http://producers.karis.xtee.riik.ee/producer/karis", clazz.TtJIsik.Count);
                for (int x = 0; ((clazz.TtJIsik != null) 
                            && (x < clazz.TtJIsik.Count)); x = (x + 1)) {
                    if (clazz.TtJIsik[x]!=null) {
                        Writer.WriteStartElement("ttJsik");
                        global::Xtee.Core.SerializationMetadata metaTtJIsik = this.GetMetaData(clazz.TtJIsik[x]);
                        Writer.WriteTypeAttribute(metaTtJIsik.TypeQualifiedName.Namespace, metaTtJIsik.TypeQualifiedName.Name);
                        metaTtJIsik.NewSerializer(clazz.TtJIsik[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("viga");
            if (clazz.Viga!=null) {
                global::Xtee.Core.SerializationMetadata metaViga = this.GetMetaData(clazz.Viga);
                Writer.WriteTypeAttribute(metaViga.TypeQualifiedName.Namespace, metaViga.TypeQualifiedName.Name);
                metaViga.NewSerializer(clazz.Viga).WriteXml(Writer);
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "ttJIsik")) {
                goto ttJIsik;
            }
            else {
                if ((Reader.LocalName == "viga")) {
                    goto viga;
                }
                else {
                    return;
                }
            }
        ttJIsik:
            if ((Reader.IsElementNil() == false)) {
                clazz.TtJIsik = new System.Collections.Generic.List<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IJisikKaristus>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ttJIsik");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "ttJsik")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>krUurijaJIsik_id_vastus>ttJIsik>ttJsik");
                        }
                        global::Xtee.Core.SerializationMetadata metaTtJIsik = this.GetMetaData<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IJisikKaristus>(Reader, "jisik_karistus", "http://producers.karis.xtee.riik.ee/producer/karis");
                        global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IJisikKaristus item = metaTtJIsik.NewEntity<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IJisikKaristus>();
                        clazz.TtJIsik.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("ttJsik");
                            metaTtJIsik.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                Reader.Skip();
            }
            goto START;
        viga:
            if ((Reader.IsElementNil() == false)) {
                global::Xtee.Core.SerializationMetadata metaViga = this.GetMetaData<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IViga>(Reader, "viga", "http://producers.karis.xtee.riik.ee/producer/karis");
                clazz.Viga = metaViga.NewEntity<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IViga>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("viga");
                    metaViga.NewSerializer(clazz.Viga).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
    }
}
